package org.zhadoop.stream.cql.semanticanalyzer.parser.visitor;

import org.antlr.v4.runtime.misc.NotNull;
import org.zhadoop.stream.cql.semanticanalyzer.parser.CQLParser.FromClauseContext;
import org.zhadoop.stream.cql.semanticanalyzer.parser.CQLParser.GroupByClauseContext;
import org.zhadoop.stream.cql.semanticanalyzer.parser.CQLParser.HavingClauseContext;
import org.zhadoop.stream.cql.semanticanalyzer.parser.CQLParser.LimitClauseContext;
import org.zhadoop.stream.cql.semanticanalyzer.parser.CQLParser.OrderByClauseContext;
import org.zhadoop.stream.cql.semanticanalyzer.parser.CQLParser.ParallelClauseContext;
import org.zhadoop.stream.cql.semanticanalyzer.parser.CQLParser.SelectClauseContext;
import org.zhadoop.stream.cql.semanticanalyzer.parser.CQLParser.WhereClauseContext;
import org.zhadoop.stream.cql.semanticanalyzer.parser.context.SelectStatementContext;

/**
 * select 语句语法结构遍历
 * 
 * @author zwd
 *
 */
public class SelectStatementVisitor extends AbsCQLParserBaseVisitor<SelectStatementContext> {
	private SelectStatementContext context = null;

	public SelectStatementVisitor() {
		context = new SelectStatementContext();
	}

	@Override
	protected SelectStatementContext defaultResult() {
		return context;
	}

	@Override
	public SelectStatementContext visitSelectClause(@NotNull SelectClauseContext ctx) {
		SelectClauseVisitor visitor = new SelectClauseVisitor();
		context.setSelect(visitor.visit(ctx));
		return context;
	}

	@Override
	public SelectStatementContext visitFromClause(@NotNull FromClauseContext ctx) {
		FromClauseVisitor visitor = new FromClauseVisitor();
		context.setFrom(visitor.visit(ctx));
		return context;
	}

	@Override
	public SelectStatementContext visitWhereClause(@NotNull WhereClauseContext ctx) {
		WhereClauseVisitor visitor = new WhereClauseVisitor();
		context.setWhere(visitor.visit(ctx));
		return context;
	}

	@Override
	public SelectStatementContext visitGroupByClause(@NotNull GroupByClauseContext ctx) {
		GroupbyClauseVisitor visitor = new GroupbyClauseVisitor();
		context.setGroupby(visitor.visit(ctx));
		return context;
	}

	@Override
	public SelectStatementContext visitHavingClause(@NotNull HavingClauseContext ctx) {
		HavingClauseVisitor visitor = new HavingClauseVisitor();
		context.setHaving(visitor.visit(ctx));
		return context;
	}

	@Override
	public SelectStatementContext visitOrderByClause(@NotNull OrderByClauseContext ctx) {
		OrderbyClauseVisitor visitor = new OrderbyClauseVisitor();
		context.setOrderby(visitor.visit(ctx));
		return context;
	}
	
	@Override
	public SelectStatementContext visitLimitClause(@NotNull LimitClauseContext ctx) {
		LimitClauseVisitor visitor = new LimitClauseVisitor();
        context.setLimit(visitor.visit(ctx));
        return context;
	}
	
	@Override
	public SelectStatementContext visitParallelClause(@NotNull ParallelClauseContext ctx) {
		ParallelClauseVisitor visitor = new ParallelClauseVisitor();
		context.setParallel(visitor.visit(ctx));
		return context;
	}

}
